<?php

/**
 * 后台首页控制器
 * Class IndexController
 * @author leiying
 * @package Admin\Controller
 */
namespace Admin\Controller;
use User\Api\UserApi as UserApi;



class IndexController extends AdminController {


    /**加载后台首页
     * @author leiying
     */
    public function index(){

        if(UID){
            $this->meta_title = '管理首页';
            static $Auth    =   null;
            if (!$Auth) {
                $Auth       =   new \Think\Auth();
            }
            if(UID == 1){
                $res = M('auth_rule')->field("type,title,name,icon,m_id,pid")->where(array('type'=>array('in',array(2,3)),'status'=>1))->order("sort asc")->select();
            }else{
                $res = $Auth->getMenuList(UID,array(2,3));
            }

            foreach($res as &$v){
//                $auth = preg_replace('/\?.*$/U','',$v['name']);
//                if ( in_array($auth,$name) && $intersect==$param ) {  //如果节点相符且url参数满足
//                    $list[] = $auth ;
//                }
                $v['name'] = "http://".$_SERVER['HTTP_HOST']."/".$v['name'];
            }

            $tree = list_to_tree($res,'m_id');

            $this->assign('lists',$tree);
            $this->display();
        } else {
            D('Member')->logout();
            session('[destroy]');
            $this->redirect('Admin/Public/login');
        }
    }

    /**欢迎页
     * @author leiying
     */
    public function welcome(){
        $res = M("apply")->field("status")->where(array("status"=>array("in",array(1,2,3,4,5,6))))->select();
        $info = array(
            "status_1" => 0,
            "status_2" => 0,
            "status_3" => 0,
            "status_4" => 0,
            "status_5" => 0,
            "status_6" => 0,
        );
        if($res){
            foreach($res as $row){
                $key = "status_".$row["status"];
                $info[$key]++;
            }
        }

        /*最后登录信息*/
        $admin_info = M("member")->where(array("uid"=>UID))->find();
        $info["admin_info"] = $admin_info;
        $this->assign('info',$info);
        $this->display();
    }

    /**访问未授权的页面
     * @author leiying
     */
    public function notAuth(){
        $this->display();
    }

}
